package com.yzk.user.service.impl;

import java.util.List;

import javax.annotation.Resource;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yzk.frame.orm.dao.GenericDAO;
import com.yzk.frame.utils.util.Page;
import com.yzk.user.model.SysUser;
import com.yzk.user.service.ISysUserSer;


@Transactional(readOnly=false)
@Service
public class SysUserSerImp implements ISysUserSer {

	private GenericDAO<SysUser,Long> dao ;
	
	@PersistenceContext
	public void setEntityManager(EntityManager entityManager) {
		dao = new GenericDAO<SysUser,Long>(entityManager,SysUser.class);
	}
	
	
	public void save(SysUser entity) {
		dao.save(entity);
		System.out.println("save sucessful!!!");
	}
	
	@Transactional(readOnly=true)
	public List<SysUser> listUser() {
		return this.dao.query("select su from SysUser su") ;
	}
	
	@Transactional(readOnly=true)
	public SysUser findById(Integer id) {
		SysUser user = this.dao.findById(id) ;
		return user;
	}
	
	public boolean delUser(Integer id) {
		return this.dao.delete(id);
	}
	
	public Page<SysUser> getByPage(Page<SysUser> page) {
		
		return page;
	}
	

	public GenericDAO<SysUser, Long> getDao() {
		return dao;
	}

//	@Resource
	public void setDao(GenericDAO<SysUser, Long> dao) {
		this.dao = dao;
	}


	
}
